package com.xoa.service.document.Impl;

import com.xoa.dao.document.DocumentOutSendRecordMapper;
import com.xoa.model.document.DocumentOutSendRecord;
import com.xoa.model.document.DocumentOutSendRecordWithBLOBs;
import com.xoa.service.document.DocumentOutSendRecordService;
import com.xoa.util.ToJson;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DocumentOutSendRecordServiceImpl implements DocumentOutSendRecordService {
    @Resource
    DocumentOutSendRecordMapper documentOutSendRecordMapper;

    //新建
    @Override
    public ToJson insert(DocumentOutSendRecordWithBLOBs documentOutSendRecord) {
        ToJson json = new ToJson();
        int insert = documentOutSendRecordMapper.insertSelective(documentOutSendRecord);
        if (insert > 0) {
            json.setFlag(0);
        } else {
            json.setFlag(1);
        }
        return json;
    }

    //删除
    @Override
    public ToJson delete(Integer recordId) {
        ToJson json = new ToJson();
        int i = documentOutSendRecordMapper.deleteByPrimaryKey(recordId);
        if (i > 0) {
            json.setFlag(0);
        } else {
            json.setFlag(1);
        }
        return json;
    }

    //更新
    @Override
    public ToJson update(DocumentOutSendRecordWithBLOBs documentOutSendRecord) {
        ToJson json = new ToJson();
        int i = documentOutSendRecordMapper.updateByPrimaryKey(documentOutSendRecord);
        if (i > 0) {
            json.setFlag(0);
        } else {
            json.setFlag(1);
        }
        return json;
    }

    //修改签收状态
    @Override
    public ToJson updateById(DocumentOutSendRecordWithBLOBs documentOutSendRecord) {
        ToJson json = new ToJson();
        int i = documentOutSendRecordMapper.updateByPrimaryKeySelective(documentOutSendRecord);
        if (i > 0) {
            json.setFlag(0);
        } else {
            json.setFlag(1);
        }
        return json;
    }

    //查询所有关于runid的数据
    public List<DocumentOutSendRecordWithBLOBs> selectByRunId(Integer runId) {
        return documentOutSendRecordMapper.selectByRunId(runId);
    }

    //查询去重的docunid
    public List<String> selectUnidByRunId(Integer runId) {
        return documentOutSendRecordMapper.selectUnidByRunId(runId);
    }
}
